package com.tsh.erp.support;

import javax.servlet.http.HttpServletRequest;

import kiven.jee.utils.common.Constants;

import com.sun.servicetag.SystemEnvironment;
import com.tsh.erp.model.User;

public class AppHelper {

	/**
	 * 根据请求对象获得Session中已存在的User
	 * 
	 * @param request
	 * @return
	 */
	public static User getAuthUser(HttpServletRequest request) {
		Object object = request.getSession().getAttribute(Constants.AUTH_USER);
		
		return object != null ? (User) object : null;
	}
	
	public static void setAuthUser(HttpServletRequest request,User user) {
		request.getSession().setAttribute(Constants.AUTH_USER, user);
	}
	
	public static String getUsername(HttpServletRequest request) {
		User user = getAuthUser(request);
		return user != null ? user.getUsername() : null;
	}
}
